from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-17 14:03:47.169275
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 17, Dec, 2021
Time: 14:03:51
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.5336
Nobs: 508.000 HQIC: -47.9892
Log likelihood: 5866.53 FPE: 1.07381e-21
AIC: -48.2831 Det(Omega_mle): 9.01015e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.354979 0.079085 4.489 0.000
L1.Burgenland 0.099623 0.043895 2.270 0.023
L1.Kärnten -0.115219 0.022595 -5.099 0.000
L1.Niederösterreich 0.179393 0.091005 1.971 0.049
L1.Oberösterreich 0.127338 0.092223 1.381 0.167
L1.Salzburg 0.282897 0.047195 5.994 0.000
L1.Steiermark 0.021458 0.060961 0.352 0.725
L1.Tirol 0.107738 0.049220 2.189 0.029
L1.Vorarlberg -0.082043 0.043365 -1.892 0.059
L1.Wien 0.029717 0.082910 0.358 0.720
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.014450 0.174881 0.083 0.934
L1.Burgenland -0.050576 0.097066 -0.521 0.602
L1.Kärnten 0.036018 0.049964 0.721 0.471
L1.Niederösterreich -0.212532 0.201240 -1.056 0.291
L1.Oberösterreich 0.466588 0.203934 2.288 0.022
L1.Salzburg 0.312621 0.104362 2.996 0.003
L1.Steiermark 0.103637 0.134804 0.769 0.442
L1.Tirol 0.313006 0.108841 2.876 0.004
L1.Vorarlberg 0.010471 0.095894 0.109 0.913
L1.Wien 0.016605 0.183338 0.091 0.928
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.220010 0.040233 5.468 0.000
L1.Burgenland 0.091259 0.022331 4.087 0.000
L1.Kärnten -0.004983 0.011495 -0.434 0.665
L1.Niederösterreich 0.223301 0.046297 4.823 0.000
L1.Oberösterreich 0.167713 0.046916 3.575 0.000
L1.Salzburg 0.037429 0.024009 1.559 0.119
L1.Steiermark 0.027158 0.031012 0.876 0.381
L1.Tirol 0.076905 0.025040 3.071 0.002
L1.Vorarlberg 0.055613 0.022061 2.521 0.012
L1.Wien 0.106895 0.042178 2.534 0.011
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163840 0.039413 4.157 0.000
L1.Burgenland 0.041803 0.021875 1.911 0.056
L1.Kärnten -0.012994 0.011260 -1.154 0.249
L1.Niederösterreich 0.150531 0.045353 3.319 0.001
L1.Oberösterreich 0.343458 0.045960 7.473 0.000
L1.Salzburg 0.099590 0.023520 4.234 0.000
L1.Steiermark 0.108632 0.030380 3.576 0.000
L1.Tirol 0.088785 0.024529 3.620 0.000
L1.Vorarlberg 0.054074 0.021611 2.502 0.012
L1.Wien -0.038097 0.041318 -0.922 0.357
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148878 0.075442 1.973 0.048
L1.Burgenland -0.038161 0.041873 -0.911 0.362
L1.Kärnten -0.036150 0.021554 -1.677 0.094
L1.Niederösterreich 0.130036 0.086813 1.498 0.134
L1.Oberösterreich 0.188019 0.087975 2.137 0.033
L1.Salzburg 0.255496 0.045021 5.675 0.000
L1.Steiermark 0.076375 0.058153 1.313 0.189
L1.Tirol 0.131366 0.046953 2.798 0.005
L1.Vorarlberg 0.105411 0.041368 2.548 0.011
L1.Wien 0.041527 0.079091 0.525 0.600
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.077553 0.059705 1.299 0.194
L1.Burgenland 0.016123 0.033139 0.487 0.627
L1.Kärnten 0.051236 0.017058 3.004 0.003
L1.Niederösterreich 0.180283 0.068704 2.624 0.009
L1.Oberösterreich 0.337116 0.069624 4.842 0.000
L1.Salzburg 0.051077 0.035630 1.434 0.152
L1.Steiermark -0.005612 0.046023 -0.122 0.903
L1.Tirol 0.124758 0.037159 3.357 0.001
L1.Vorarlberg 0.059169 0.032739 1.807 0.071
L1.Wien 0.109765 0.062593 1.754 0.079
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169497 0.072464 2.339 0.019
L1.Burgenland 0.011058 0.040220 0.275 0.783
L1.Kärnten -0.060786 0.020703 -2.936 0.003
L1.Niederösterreich -0.110933 0.083386 -1.330 0.183
L1.Oberösterreich 0.234769 0.084502 2.778 0.005
L1.Salzburg 0.039891 0.043243 0.922 0.356
L1.Steiermark 0.262673 0.055857 4.703 0.000
L1.Tirol 0.488284 0.045099 10.827 0.000
L1.Vorarlberg 0.069817 0.039735 1.757 0.079
L1.Wien -0.101430 0.075968 -1.335 0.182
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.142158 0.080130 1.774 0.076
L1.Burgenland -0.013155 0.044475 -0.296 0.767
L1.Kärnten 0.063405 0.022894 2.770 0.006
L1.Niederösterreich 0.173229 0.092208 1.879 0.060
L1.Oberösterreich -0.079491 0.093442 -0.851 0.395
L1.Salzburg 0.224195 0.047818 4.688 0.000
L1.Steiermark 0.134484 0.061767 2.177 0.029
L1.Tirol 0.052753 0.049871 1.058 0.290
L1.Vorarlberg 0.141061 0.043938 3.210 0.001
L1.Wien 0.165122 0.084005 1.966 0.049
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.458718 0.044422 10.326 0.000
L1.Burgenland -0.001149 0.024656 -0.047 0.963
L1.Kärnten -0.013928 0.012692 -1.097 0.272
L1.Niederösterreich 0.178339 0.051118 3.489 0.000
L1.Oberösterreich 0.261878 0.051802 5.055 0.000
L1.Salzburg 0.018662 0.026509 0.704 0.481
L1.Steiermark -0.011459 0.034242 -0.335 0.738
L1.Tirol 0.072466 0.027647 2.621 0.009
L1.Vorarlberg 0.056560 0.024358 2.322 0.020
L1.Wien -0.018379 0.046570 -0.395 0.693
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.028841 0.093179 0.154718 0.140734 0.066681 0.080358 0.014523 0.208853
Kärnten 0.028841 1.000000 -0.034528 0.131866 0.049835 0.074243 0.454579 -0.080184 0.098454
Niederösterreich 0.093179 -0.034528 1.000000 0.279978 0.100277 0.253987 0.050188 0.143276 0.247919
Oberösterreich 0.154718 0.131866 0.279978 1.000000 0.194698 0.283278 0.156782 0.125604 0.188592
Salzburg 0.140734 0.049835 0.100277 0.194698 1.000000 0.120170 0.059411 0.108982 0.067124
Steiermark 0.066681 0.074243 0.253987 0.283278 0.120170 1.000000 0.132243 0.088966 0.007619
Tirol 0.080358 0.454579 0.050188 0.156782 0.059411 0.132243 1.000000 0.064083 0.125485
Vorarlberg 0.014523 -0.080184 0.143276 0.125604 0.108982 0.088966 0.064083 1.000000 -0.009527
Wien 0.208853 0.098454 0.247919 0.188592 0.067124 0.007619 0.125485 -0.009527 1.000000